﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using DTO;

namespace GUI
{
    public partial class FormTraCuuThongTinChuyenXe : Form
    {
        public static DateTime ngDi;
        public static String mChuyen;
        public static String sHieu;
        public static int flag;
        public int row;
        public FormTraCuuThongTinChuyenXe()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void FormTraCuuThongTinChuyenXe_Load(object sender, EventArgs e)
        {
            List<ChuyenXeDTO> lx = ChuyenXeBUS.SelectMa();
            foreach (var item in lx)
            {
                this.cbbmachuyen.Items.Add(item.MACHUYEN);
                this.cbbbdi.Items.Add(item.BENXEDI);
                this.cbbbden.Items.Add(item.BENXEDEN);
            }
            
            List<String> mc = ChuyenXeBUS.SelectALLMaChuyen();
        }

        private void btnxem_Click(object sender, EventArgs e)
        {
            this.dataGridView1.Columns.Clear();
            if (rbnmachuyen.Checked == true)
            {
                int tong = 0;
                String machuyen = cbbmachuyen.Text.ToString();
                try
                {
                    this.dataGridView1.DataSource = TongHopBUS.SelectSoLuongChuyentheoma(machuyen, ref tong);
                    lbkq.Text = tong.ToString();
                    this.lbkq.Text = tong.ToString();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

            }
            if (rbnbdi.Checked == true)
            {
                int tong = 0;
                String bendi = cbbbdi.Text.ToString();
                try
                {
                    this.dataGridView1.DataSource = TongHopBUS.SelectSoLuongChuyentheobendi(bendi, ref tong);
                    lbkq.Text = tong.ToString();
                    this.lbkq.Text = tong.ToString();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            if (rbnbden.Checked == true)
            {
                int tong = 0;
                String benden = cbbbden.Text.ToString();
                try
                {
                    this.dataGridView1.DataSource = TongHopBUS.SelectSoLuongChuyentheobenden(benden, ref tong);
                    lbkq.Text = tong.ToString();
                    this.lbkq.Text = tong.ToString();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            if (rbntrongtai.Checked == true)
            {
                int tong = 0;
                
                int bdkg = Convert.ToInt32(txtbdkg.Text);
                int ktkg = Convert.ToInt32(txtktkg.Text);
                try
                {
                    this.dataGridView1.DataSource = TongHopBUS.SelectSoLuongChuyentheotrongluong(bdkg,ktkg,ref tong);
                    lbkq.Text = tong.ToString();
                    this.lbkq.Text = tong.ToString();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}
